package ui;
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.*;


import controller.MobilePlanSellAndBillSystem;
import customexceptions.PlanAlreadyExistsException;

/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
@SuppressWarnings("serial")
public class CreateTitularPlansUI extends javax.swing.JFrame {
	private JTextField jTextFieldPlanNumber;
	private JButton jButtonAccept;
	private JLabel jLabelPlanNumber;
	private JTextField jTextFieldPlanCost;
	private JLabel jLabelPlanCost;
	private JTextField jTextFieldPlanDiscount;
	private JLabel jLabelPlanDiscount;
	private MobilePlanSellAndBillSystem system;

	/**
	* Auto-generated main method to display this JFrame
	*/
	public static void main(String[] args) {
		SwingUtilities.invokeLater(new Runnable() {
			public void run() {
				CreateTitularPlansUI inst = new CreateTitularPlansUI();
				inst.setLocationRelativeTo(null);
				inst.setVisible(true);
			}
		});
	}
	public CreateTitularPlansUI(){
		
	}
	public CreateTitularPlansUI(MobilePlanSellAndBillSystem system) {
		super();
		initGUI();
		this.system = system;
	}
	
	private void initGUI() {
		try {
			setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
			getContentPane().setLayout(null);
			{
				jTextFieldPlanNumber = new JTextField();
				getContentPane().add(jTextFieldPlanNumber);
				jTextFieldPlanNumber.setBounds(138, 47, 333, 28);
			}
			{
				jLabelPlanNumber = new JLabel();
				getContentPane().add(jLabelPlanNumber);
				jLabelPlanNumber.setText("Plan Description");
				jLabelPlanNumber.setBounds(12, 59, 99, 16);
			}
			{
				jTextFieldPlanCost = new JTextField();
				getContentPane().add(jTextFieldPlanCost);
				jTextFieldPlanCost.setBounds(138, 87, 333, 28);
			}
			{
				jLabelPlanCost = new JLabel();
				getContentPane().add(jLabelPlanCost);
				jLabelPlanCost.setText("Plan Cost");
				jLabelPlanCost.setBounds(12, 99, 67, 16);
			}		
			{
				jTextFieldPlanDiscount = new JTextField();
				getContentPane().add(jTextFieldPlanDiscount);
				jTextFieldPlanDiscount.setBounds(138, 137, 333, 28);
			}

			{
				jLabelPlanDiscount = new JLabel();
				getContentPane().add(jLabelPlanDiscount);
				jLabelPlanDiscount.setText("Plan Discount");
				jLabelPlanDiscount.setBounds(12, 149, 114, 16);
			}				
			{
				jButtonAccept = new JButton();
				getContentPane().add(jButtonAccept);
				jButtonAccept.setText("Create");
				jButtonAccept.setBounds(204, 194, 84, 23);

				jButtonAccept.addActionListener(new ActionListener()
				{
					public void actionPerformed(ActionEvent evt) 
					{
							try {
									system.createTitularPlan(jTextFieldPlanNumber.getText(), 
													Float.parseFloat(jTextFieldPlanCost.getText()),
													Float.parseFloat(jTextFieldPlanDiscount.getText())
											
											);

							} catch (PlanAlreadyExistsException e) {
								ErrorReportView errorReportView = new ErrorReportView(e.getErrorMessage());
								errorReportView.setVisible(true);
							}

							jTextFieldPlanNumber.setText("");
							jTextFieldPlanCost.setText("");
							jTextFieldPlanDiscount.setText("");

					}
				});
				
			}
			pack();
			this.setSize(506, 294);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

}
